home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
By Popular Request 2.0
/
By Popular Request 2.0 (Arsenal Computer).ISO
/
amiga_5
/
selct102.lha
/
Select
/
Source
/
Select.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-25
|
30KB
|
1,278 lines
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <devices/timer.h>
#include <dos/dos.h>
#include <exec/lists.h>
#include <exec/memory.h>
#include <exec/nodes.h>
#include <intuition/gadgetclass.h>
#include <intuition/intuitionbase.h>
#include <workbench/workbench.h>
#include <workbench/startup.h>
#include <proto/commodities.h>
#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/gadtools.h>
#include <proto/graphics.h>
#include <proto/icon.h>
#include <proto/intuition.h>
/********************************************************************/
/*** Program: Select ***/
/*** Version: 1.02 ***/
/*** Author: Torsten Kramer ***/
/*** ***/
/*** Copyright 1995 by Torsten Kramer ***/
/*** ***/
/*** Version history: ***/
/*** 0.01 - 19.12.1994: - 1. Testversion ***/
/*** 0.02 - 17.01.1995: - Aktualisierung durch Timer raus ***/
/*** 1.00 - 19.01.1995: - 1. Release ***/
/*** 1.01 - 21.03.1995: - Aktualisierung durch Timer rein ***/
/*** - ESC wird unterstⁿtzt ***/
/*** - Option PUBSCREEN eingebaut ***/
/*** 1.02 - 25.04.1995: - NewLookMenus ***/
/*** - Window hat unter 2.x die richtige ***/
/*** Gr÷▀e ***/
/*** - Window wird auf Default-Publicscreen ***/
/*** ge÷ffnet, wenn Option PUBSCREEN nicht ***/
/*** angegeben ist ***/
/********************************************************************/
#define PROG_NAME "Select"
#define PROG_VERSION "1.02"
#define PROG_DATE "25.04.95"
#define PROG_DESCR "Helps to handle screens and windows"
#define DEF_HOTKEY "ctrl alt s"
#define TEMPLATE "CX_POPUP/K,CX_POPKEY/K,CX_PRIORITY/N/K,PUBSCREEN/K"
#define OPT_POPUP 0
#define OPT_HOTKEY 1
#define OPT_PRIORITY 2
#define OPT_PUBSCREEN 3
#define NUM_OPTS 4
#define WIN_IDCMP IDCMP_VANILLAKEY | IDCMP_RAWKEY | IDCMP_REFRESHWINDOW | \
IDCMP_CLOSEWINDOW | IDCMP_MENUPICK | LISTVIEWIDCMP
#define ID_LISTVIEW 0
#define MENU_PROJECT 0
#define ITEM_NEWSHELL 0
#define ITEM_HIDE 1
#define ITEM_ABOUT 2
#define ITEM_QUIT 4
#define PRI_WINDOWS 1
#define PRI_TITLE_WINDOWS 2
#define PRI_SCREENS 3
#define PRI_TITLE_SCREENS 4
#define EVT_HOTKEY 1L
#define ESC 0x1b
#define CURSOR_UP 0x4c
#define CURSOR_DOWN 0x4d
#define ENTER 0x0d
#define max(a,b) ((a)>(b)?(a):(b))
/**********************************************************/
/* Prototypes */
/**********************************************************/
BOOL open_libs(void);
void close_libs(void);
BOOL read_args(int, char **);
BOOL open_device(void);
void close_device(void);
BOOL setup_cx(void);
void free_cx(void);
BOOL open_interface(void);
void close_interface(void);
BOOL gadgets(void);
BOOL menu(void);
void refresh_listview(void);
BOOL create_item_list(void);
void free_nodes(void);
void newshell(void);
void timer(void);
void click_to_front(UWORD);
void select_label(void);
void about(void);
void process_msg(void);
/**********************************************************/
/* Structures */
/**********************************************************/
struct NewGadget ng;
struct NewMenu NewMenu[] =
{
{NM_TITLE, "Project", 0 , 0, 0, 0},
{NM_ITEM, "Newshell", "N" , 0, 0, 0},
{NM_ITEM, "Hide", "H" , 0, 0, 0},
{NM_ITEM, "About...", "A" , 0, 0, 0},
{NM_ITEM, NM_BARLABEL, 0 , 0, 0, 0},
{NM_ITEM, "Quit", "Q" , 0, 0, 0},
{NM_END, NULL, 0 , 0, 0, 0}
};
struct TextAttr Topaz80 =
{
"topaz.font",
8,
0,
0
};
struct NewBroker NewBroker =
{
NB_VERSION, /* nb_Version - Version of the NewBroker structure¢ */
PROG_NAME, /* nb_Name - Name Commodities uses to identify this commodity */
PROG_NAME, /* nb_Title - Title of commodity that appears in CXExchange */
PROG_DESCR, /* nb_Descr - Description of the commodity */
NBU_UNIQUE | NBU_NOTIFY, /* nb_Unique - Tells CX not to launch another commodity with same name */
COF_SHOW_HIDE, /* nb_Flags - Tells CX if this commodity has a window */
0, /* nb_Pri - This commodity's priority */
0, /* nb_Port - MsgPort CX talks to */
0 /* nb_ReservedChannel - reserved for later use */
};
struct ItemNode
{
struct Node node;
APTR Item;
UBYTE ItemName[80];
};
/**********************************************************/
/* Variables */
/**********************************************************/
/*---------*/
/* Strings */
/*---------*/
char __stdiowin[] = "CON:0/11/640/80/"
PROG_NAME " " PROG_VERSION;
static const char Version[] = "\0$VER: " PROG_NAME " "
PROG_VERSION " (" PROG_DATE ")\0";
char Title[80];
/*-----------*/
/* Libraries */
/*-----------*/
struct Library *IconBase = NULL,
*CxBase = NULL,
*GadToolsBase = NULL;
struct GfxBase *GfxBase = NULL;
struct IntuitionBase *IntuitionBase = NULL;
/*---------*/
/* Devices */
/*---------*/
struct timerequest *TimerIO = NULL;
struct MsgPort *TimerMP = NULL;
/*-------*/
/* Lists */
/*-------*/
struct ItemNode *WorkNode, *NextNode;
struct List *ItemList = NULL;
/*--------------------------------*/
/* Screens, Windows, Gadgets, ... */
/*--------------------------------*/
struct Window *Win = NULL,
*NextWindow,
*ActiveWin;
struct Screen *Scr = NULL,
*NextScreen;
APTR *VisualInfo = NULL;
struct Menu *MenuStrip = NULL;
struct Gadget *GList = NULL,
*ListViewGad;
char GadgetText[] = "Screen & Window List";
WORD WinLeft = 100,
WinTop = 50,
WinHeight,
WinWidth;
/*-------------*/
/* Commodities */
/*-------------*/
CxObj *Broker = NULL;
CxMsg *BrokerMsg = NULL;
struct MsgPort *BrokerMP = NULL;
/*------*/
/* Misc */
/*------*/
int ReturnCode = RETURN_OK;
LONG DevError = -1,
OptPriority = 0;
UWORD NumLabels,
SelectedLabel = 0;
char OptHotKey[40] = DEF_HOTKEY,
OptPubScreen[40]= "\0";
BOOL OptPopup = TRUE,
CxActive,
Interface = FALSE,
RequestSent = FALSE;
/**********************************************************/
/* main */
/**********************************************************/
int main (int argc, char *argv[])
{
if (open_libs())
{
if (read_args(argc, argv))
{
if (open_device())
{
if (setup_cx())
{
if (OptPopup)
open_interface();
if ((OptPopup && Interface) || (! OptPopup))
process_msg();
}
}
}
}
close_interface();
free_cx();
close_device();
close_libs();
return(ReturnCode);
}
/**********************************************************/
/* open_libs */
/**********************************************************/
BOOL open_libs(void)
{
if ((CxBase = OpenLibrary("commodities.library", 37)) != NULL)
{
if ((GadToolsBase = OpenLibrary("gadtools.library", 37)) != NULL)
{
if ((IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 37)) != NULL)
{
if ((GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 37)) != NULL)
{
if ((IconBase = OpenLibrary("icon.library", 37)) != NULL)
{
return(TRUE);
}
}
}
}
}
PrintFault(ERROR_INVALID_RESIDENT_LIBRARY, NULL);
ReturnCode = RETURN_FAIL;
return(FALSE);
}
/**********************************************************/
/* close_libs */
/**********************************************************/
void close_libs(void)
{
if (CxBase != NULL) CloseLibrary(CxBase);
if (GadToolsBase != NULL) CloseLibrary(GadToolsBase);
if (IntuitionBase != NULL) CloseLibrary((struct Library *)IntuitionBase);
if (GfxBase != NULL) CloseLibrary((struct Library *)GfxBase);
if (IconBase != NULL) CloseLibrary(IconBase);
}
/**********************************************************/
/* read_args */
/**********************************************************/
BOOL read_args(int argc, char *argv[])
{
struct WBStartup *WBenchMsg;
struct WBArg *WBenchArg;
struct DiskObject *DiskObj;
char **ToolArray, *ToolValue;
struct RDArgs *RDA;
LONG OptArray[NUM_OPTS], Error, OldDir;
char No[] = "NO";
/* Set default values */
OptArray[OPT_POPUP] = (LONG)"YES";
OptArray[OPT_HOTKEY] = NULL;
OptArray[OPT_PRIORITY] = 0;
OptArray[OPT_PUBSCREEN] = NULL;
if (argc == 0)
{
/* The program was started from the Workbench */
WBenchMsg = (struct WBStartup *)argv;
WBenchArg = WBenchMsg->sm_ArgList;
/* Process only the first argument (our tool). Ignore */
/* any additional args which are icons passed to us */
/* via either extend select or default tool method. */
if (WBenchArg->wa_Name != NULL)
{
/* Change to the directory where the file is stored */
if (WBenchArg->wa_Lock != NULL)
{
OldDir = CurrentDir(WBenchArg->wa_Lock);
}
else
OldDir = -1;
/* Read DiskObject structure (.info file) */
if ((DiskObj = GetDiskObject(WBenchArg->wa_Name)) != NULL)
{
/* Get the pointer to the ToolType array */
ToolArray = DiskObj->do_ToolTypes;
/* Check for ToolTypes we need and get the */
/* value(s) of the ToolTypes. */
if ((ToolValue = FindToolType(ToolArray, "CX_POPUP")) != NULL)
if (MatchToolValue(ToolValue, No))
OptPopup = FALSE;
if ((ToolValue = FindToolType(ToolArray, "CX_POPKEY")) != NULL)
if (strlen(ToolValue) < 40)
strcpy(OptHotKey, ToolValue);
if ((ToolValue = FindToolType(ToolArray, "CX_PRIORITY")) != NULL)
OptPriority = atol(ToolValue);
if ((ToolValue = FindToolType(ToolArray, "PUBSCREEN")) != NULL)
if (strlen(ToolValue) < 40)
strcpy(OptPubScreen, ToolValue);
FreeDiskObject(DiskObj);
}
/* Change back to the original directory */
if (OldDir != -1)
CurrentDir(OldDir);
}
}
else
{
/* The program was started from the Shell */
if ((RDA = ReadArgs(TEMPLATE, OptArray, NULL)))
{
/* The user typed a valid command line */
if (stricmp((char *)OptArray[OPT_POPUP], No) == NULL)
OptPopup = FALSE;
if (OptArray[OPT_HOTKEY] != NULL)
if (strlen((char *)OptArray[OPT_HOTKEY]) < 40)
strcpy(OptHotKey, (char *)OptArray[OPT_HOTKEY]);
if (OptArray[OPT_PUBSCREEN] != NULL)
if (strlen((char *)OptArray[OPT_PUBSCREEN]) < 40)
strcpy(OptPubScreen, (char *)OptArray[OPT_PUBSCREEN]);
OptPriority = OptArray[OPT_PRIORITY];
FreeArgs(RDA);
}
else
{
/* There is an error in the command line */
Error = IoErr();
PrintFault(Error, argv[0]);
ReturnCode = RETURN_FAIL;
return(FALSE);
}
}
return(TRUE);
}
/**********************************************************/
/* open_device */
/**********************************************************/
BOOL open_device(void)
{
if (ItemList = AllocMem(sizeof(struct List), MEMF_PUBLIC | MEMF_CLEAR))
{
NewList(ItemList);
if (TimerMP = CreateMsgPort())
{
if (TimerIO = (struct timerequest *)CreateIORequest(TimerMP, sizeof(struct timerequest)))
{
if ((DevError = OpenDevice("timer.device", UNIT_VBLANK, (struct IORequest *)TimerIO, 0)) == 0)
{
return(TRUE);
}
}
}
}
ReturnCode = RETURN_FAIL;
return(FALSE);
}
/**********************************************************/
/* close_device */
/**********************************************************/
void close_device(void)
{
if (RequestSent)
{
if (CheckIO((struct IORequest *)TimerIO) == NULL)
{
AbortIO((struct IORequest *)TimerIO);
}
WaitIO((struct IORequest *)TimerIO);
}
if (DevError != -1) CloseDevice((struct IORequest *)TimerIO);
if (TimerIO != NULL) DeleteIORequest(TimerIO);
if (TimerMP != NULL) DeleteMsgPort(TimerMP);
if (ItemList != NULL)
{
free_nodes();
if (ItemList != NULL) FreeMem(ItemList, sizeof(struct List));
}
}
/**********************************************************/
/* setup_cx */
/**********************************************************/
BOOL setup_cx(void)
{
CxObj *Filter, *Sender, *Translate;
if ((BrokerMP = CreateMsgPort()))
{
if (OptPriority < -128 || OptPriority > 127)
OptPriority = 0;
NewBroker.nb_Pri = OptPriority;
NewBroker.nb_Port = BrokerMP;
/* create the title of the cx window */
sprintf(Title, "%s: Hot Key = <%s>", PROG_NAME, OptHotKey);
if ((Broker = CxBroker(&NewBroker, NULL)))
{
if ((Filter = CxFilter(OptHotKey)))
{
AttachCxObj(Broker, Filter);
if ((Sender = CxSender(BrokerMP, EVT_HOTKEY)))
{
AttachCxObj(Filter, Sender);
if ((Translate = CxTranslate(NULL)))
{
AttachCxObj(Filter, Translate);
if (CxObjError(Filter) == NULL)
{
ActivateCxObj(Broker, 1);
CxActive = TRUE;
return(TRUE);
}
}
}
}
}
}
ReturnCode = RETURN_FAIL;
return(FALSE);
}
/**********************************************************/
/* free_cx */
/**********************************************************/
void free_cx(void)
{
if (Broker != NULL)
DeleteCxObjAll(Broker);
if (BrokerMP != NULL)
{
while ((BrokerMsg = (CxMsg *)GetMsg(BrokerMP)))
ReplyMsg((struct Message *)BrokerMsg);
DeletePort(BrokerMP);
}
}
/**********************************************************/
/* open_interface */
/**********************************************************/
BOOL open_interface(void)
{
UWORD DispWidth, DispHeight;
ULONG ScreenModeID;
struct Rectangle Rect;
if (IntuitionBase->ActiveWindow != Win)
ActiveWin = IntuitionBase->ActiveWindow;
if (Win == NULL)
{
if ((Scr = LockPubScreen(OptPubScreen)) == NULL)
Scr = LockPubScreen(NULL);
if (Scr)
{
if (VisualInfo = GetVisualInfo(Scr, TAG_END))
{
if (gadgets())
{
if (menu())
{
if((ScreenModeID = GetVPModeID(&Scr->ViewPort)) != INVALID_ID)
{
if(QueryOverscan(ScreenModeID, &Rect, OSCAN_TEXT))
{
DispWidth = Rect.MaxX - Rect.MinX + 1;
DispHeight = Rect.MaxY - Rect.MinY + 1;
WinLeft = Scr->MouseX;
WinTop = Scr->MouseY;
if (WinLeft < -Scr->LeftEdge)
{
WinLeft = max(0, -Scr->LeftEdge);
WinLeft = WinLeft + 100;
}
if (WinTop < -Scr->TopEdge)
{
WinTop = max(0, -Scr->TopEdge);
WinTop = WinTop + 50;
}
if ((WinLeft + WinWidth) > (DispWidth + -Scr->LeftEdge))
{
WinLeft = (DispWidth + -Scr->LeftEdge) - WinWidth;
}
if ((WinTop + WinHeight) > (DispHeight + -Scr->TopEdge))
{
WinTop = (DispHeight + -Scr->TopEdge) - WinHeight;
}
}
}
if (Win = OpenWindowTags(NULL,
WA_PubScreen, Scr,
WA_Left, WinLeft,
WA_Top, WinTop,
WA_Height, WinHeight,
WA_Width, WinWidth,
WA_Gadgets, GList,
WA_Title, Title,
WA_IDCMP, WIN_IDCMP,
WA_NewLookMenus, TRUE,
WA_Flags, WFLG_CLOSEGADGET | WFLG_DEPTHGADGET |
WFLG_ACTIVATE | WFLG_DRAGBAR | WFLG_SMART_REFRESH,
TAG_DONE))
{
GT_RefreshWindow(Win, NULL);
if(SetMenuStrip(Win, MenuStrip))
{
WindowToFront(Win);
ScreenToFront(Win->WScreen);
Interface = TRUE;
refresh_listview();
return(TRUE);
}
}
}
}
}
}
close_interface();
return(FALSE);
}
else
{
WindowToFront(Win);
ActivateWindow(Win);
ScreenToFront(Win->WScreen);
refresh_listview();
return(TRUE);
}
}
/**********************************************************/
/* close_interface */
/**********************************************************/
void close_interface(void)
{
if(Win != NULL)
{
ClearMenuStrip(Win);
CloseWindow(Win);
Win = NULL;
}
if (MenuStrip != NULL)
{
FreeMenus(MenuStrip);
MenuStrip = NULL;
}
if (GList != NULL)
{
FreeGadgets(GList);
GList = NULL;
}
if (VisualInfo != NULL)
{
FreeVisualInfo(VisualInfo);
VisualInfo = NULL;
}
if (Scr != NULL)
{
UnlockPubScreen(NULL, Scr);
Scr = NULL;
}
Interface = FALSE;
}
/**********************************************************/
/* gadgets */
/**********************************************************/
BOOL gadgets(void)
{
WORD PixLength;
struct Gadget *Gad;
PixLength = TextLength(&Scr->RastPort, GadgetText, strlen(GadgetText));
/* Listview gadget */
ng.ng_LeftEdge = 16;
ng.ng_TopEdge = Scr->WBorTop + (Scr->Font->ta_YSize * 2 + INTERHEIGHT * 2);
ng.ng_Width = PixLength * 2;
ng.ng_Height = Scr->Font->ta_YSize * 16;
ng.ng_GadgetText = GadgetText;
ng.ng_TextAttr = Scr->Font;
ng.ng_GadgetID = ID_LISTVIEW;
ng.ng_Flags = 0;
ng.ng_UserData = NULL;
ng.ng_VisualInfo = VisualInfo;
Gad = CreateContext(&GList);
Gad = ListViewGad = CreateGadget(LISTVIEW_KIND, Gad, &ng,
GTLV_Labels, NULL,
GTLV_ShowSelected, NULL,
GTLV_Selected, 0,
TAG_END);
if (Gad != NULL)
{
WinHeight = ng.ng_TopEdge + ng.ng_Height + INTERHEIGHT * 2;
WinWidth = ng.ng_LeftEdge + ng.ng_Width + INTERWIDTH * 2;
return(TRUE);
}
else
return(FALSE);
}
/**********************************************************/
/* menu */
/**********************************************************/
BOOL menu(void)
{
if ((MenuStrip = CreateMenus(NewMenu, TAG_END)))
{
if (LayoutMenus(MenuStrip, VisualInfo,
GTMN_NewLookMenus, TRUE,
TAG_END))
{
return(TRUE);
}
}
return(FALSE);
}
/**********************************************************/
/* refresh_listview */
/**********************************************************/
void refresh_listview(void)
{
GT_SetGadgetAttrs(ListViewGad, Win, NULL,
GTLV_Labels, ~0,
TAG_END);
if (create_item_list())
{
if (SelectedLabel > (NumLabels - 1))
SelectedLabel = NumLabels - 1;
GT_SetGadgetAttrs(ListViewGad, Win, NULL,
GTLV_Labels, ItemList,
GTLV_Selected, SelectedLabel,
TAG_END);
}
}
/**********************************************************/
/* create_item_list */
/**********************************************************/
BOOL create_item_list(void)
{
free_nodes();
NumLabels = 0;
if ((WorkNode = AllocMem(sizeof(struct ItemNode), MEMF_PUBLIC | MEMF_CLEAR)))
{
WorkNode->node.ln_Pri = PRI_TITLE_SCREENS;
WorkNode->node.ln_Type = NT_USER;
WorkNode->Item = NULL;
strcpy(WorkNode->ItemName, "(Screens)");
WorkNode->node.ln_Name = WorkNode->ItemName;
Enqueue(ItemList, (struct Node *)WorkNode);
NumLabels++;
if ((WorkNode = AllocMem(sizeof(struct ItemNode), MEMF_PUBLIC | MEMF_CLEAR)))
{
WorkNode->node.ln_Pri = PRI_TITLE_WINDOWS;
WorkNode->node.ln_Type = NT_USER;
WorkNode->Item = NULL;
strcpy(WorkNode->ItemName, "(Windows)");
WorkNode->node.ln_Name = WorkNode->ItemName;
Enqueue(ItemList, (struct Node *)WorkNode);
NumLabels++;
if (IntuitionBase->FirstScreen != NULL)
{
NextScreen = IntuitionBase->FirstScreen;
while (NextScreen != NULL)
{
if ((WorkNode = AllocMem(sizeof(struct ItemNode), MEMF_PUBLIC | MEMF_CLEAR)))
{
WorkNode->node.ln_Pri = PRI_SCREENS;
WorkNode->node.ln_Type = NT_USER;
WorkNode->Item = NextScreen;
strcpy(WorkNode->ItemName, " ");
if (NextScreen->Title != NULL)
strncat(WorkNode->ItemName, NextScreen->Title, 77);
else
strcat(WorkNode->ItemName, "<no title>");
WorkNode->node.ln_Name = WorkNode->ItemName;
Enqueue(ItemList, (struct Node *)WorkNode);
NumLabels++;
if (NextScreen->FirstWindow != NULL)
{
NextWindow = NextScreen->FirstWindow;
while (NextWindow != NULL)
{
if ((WorkNode = AllocMem(sizeof(struct ItemNode), MEMF_PUBLIC | MEMF_CLEAR)))
{
WorkNode->node.ln_Pri = PRI_WINDOWS;
WorkNode->node.ln_Type = NT_USER;
WorkNode->Item = NextWindow;
if (NextWindow != ActiveWin)
strcpy(WorkNode->ItemName, " ");
else
strcpy(WorkNode->ItemName, "> ");
if (NextWindow->Title != NULL)
strncat(WorkNode->ItemName, NextWindow->Title, 77);
else
strcat(WorkNode->ItemName, "<no title>");
WorkNode->node.ln_Name = WorkNode->ItemName;
Enqueue(ItemList, (struct Node *)WorkNode);
NumLabels++;
NextWindow = NextWindow->NextWindow;
}
else
return(FALSE);
}
}
NextScreen = NextScreen->NextScreen;
}
else
return(FALSE);
}
}
}
else
return(FALSE);
}
else
return(FALSE);
return(TRUE);
}
/**********************************************************/
/* free_nodes */
/**********************************************************/
void free_nodes(void)
{
WorkNode = (struct ItemNode *)ItemList->lh_Head;
while ((NextNode = (struct ItemNode *)WorkNode->node.ln_Succ))
{
Remove((struct Node *)WorkNode);
FreeMem(WorkNode, sizeof(struct ItemNode));
WorkNode = NextNode;
}
}
/**********************************************************/
/* newshell */
/**********************************************************/
void newshell(void)
{
Execute("Newshell", NULL, NULL);
}
/**********************************************************/
/* timer */
/**********************************************************/
void timer(void)
{
if (CxActive && Interface)
{
TimerIO->tr_node.io_Command = TR_ADDREQUEST;
TimerIO->tr_time.tv_secs = 1;
TimerIO->tr_time.tv_micro = 0;
SendIO((struct IORequest *)TimerIO);
RequestSent = TRUE;
}
}
/**********************************************************/
/* click_to_front */
/**********************************************************/
void click_to_front(UWORD ItemNumber)
{
struct Window *FirstWindow;
WorkNode = (struct ItemNode *)ItemList->lh_Head;
for (ItemNumber; ItemNumber > 0; ItemNumber--)
WorkNode = (struct ItemNode *)WorkNode->node.ln_Succ;
switch (WorkNode->node.ln_Pri)
{
case PRI_WINDOWS:
if ((struct Window *)WorkNode->Item != Win)
{
ScreenToFront(((struct Window *)WorkNode->Item)->WScreen);
WindowToFront((struct Window *)WorkNode->Item);
ActivateWindow((struct Window *)WorkNode->Item);
Interface = FALSE;
}
break;
case PRI_SCREENS:
ScreenToFront((struct Screen *)WorkNode->Item);
if (((struct Screen *)WorkNode->Item)->FirstWindow != Win)
FirstWindow = ((struct Screen *)WorkNode->Item)->FirstWindow;
else
FirstWindow = ((struct Screen *)WorkNode->Item)->FirstWindow->NextWindow;
if (FirstWindow != NULL)
{
WindowToFront(FirstWindow);
ActivateWindow(FirstWindow);
}
Interface = FALSE;
break;
default:
break;
}
}
/**********************************************************/
/* select_label */
/**********************************************************/
void select_label(void)
{
if (Interface)
GT_SetGadgetAttrs(ListViewGad, Win, NULL,
GTLV_Selected, SelectedLabel,
GTLV_MakeVisible, SelectedLabel,
TAG_END);
}
/**********************************************************/
/* about */
/**********************************************************/
void about(void)
{
struct EasyStruct Req =
{
sizeof(struct EasyStruct),
0,
"About",
"%s\n\nVersion %s (%s)\n\nAuthor: Torsten Kramer\neMail: torstenk@enterp.gun.de\n\nThis program is freeware.\nCopyright 1995 by Torsten Kramer.",
"OK"
};
EasyRequest(Win, &Req, NULL, PROG_NAME, PROG_VERSION, PROG_DATE);
}
/**********************************************************/
/* process_msg */
/**********************************************************/
void process_msg(void)
{
struct IntuiMessage *IMsg;
APTR IAdr;
ULONG MsgClass, MsgID, MsgType,
CxSigFlag, WinSigFlag, TimerSigFlag,
Signals, SigReceived;
UWORD Code;
BOOL Done = TRUE;
CxSigFlag = 1L << BrokerMP->mp_SigBit;
TimerSigFlag = 1L << TimerMP->mp_SigBit;
while (Done)
{
if (Interface)
{
WinSigFlag = 1L << Win->UserPort->mp_SigBit;
Signals = SIGBREAKF_CTRL_C | CxSigFlag | TimerSigFlag | WinSigFlag;
}
else
{
close_interface();
Signals = SIGBREAKF_CTRL_C | CxSigFlag | TimerSigFlag;
}
if (RequestSent == FALSE)
timer();
SigReceived = Wait(Signals);
if (SigReceived & TimerSigFlag)
{
/* Cleanup the port */
WaitIO((struct IORequest *)TimerIO);
RequestSent = FALSE;
if(Interface)
refresh_listview();
}
if (SigReceived & WinSigFlag)
{
while (IMsg = GT_GetIMsg(Win->UserPort))
{
Code = IMsg->Code;
MsgClass = IMsg->Class;
IAdr = IMsg->IAddress;
GT_ReplyIMsg(IMsg);
switch (MsgClass)
{
case IDCMP_CLOSEWINDOW:
Interface = FALSE;
break;
case IDCMP_MENUPICK:
if (Code != MENUNULL)
{
switch (MENUNUM(Code))
{
case MENU_PROJECT:
switch (ITEMNUM(Code))
{
case ITEM_HIDE:
Interface = FALSE;
break;
case ITEM_NEWSHELL:
newshell();
Interface = FALSE;
break;
case ITEM_ABOUT:
about();
break;
case ITEM_QUIT:
Done = FALSE;
break;
default:
break;
}
break;
default:
break;
}
}
break;
case IDCMP_GADGETUP:
switch (((struct Gadget *)IAdr)->GadgetID)
{
case ID_LISTVIEW:
click_to_front(Code);
SelectedLabel = Code;
break;
default:
break;
}
break;
case IDCMP_RAWKEY:
switch (Code)
{
case CURSOR_UP:
if (SelectedLabel > 0)
SelectedLabel--;
select_label();
break;
case CURSOR_DOWN:
if (SelectedLabel < (NumLabels - 1))
SelectedLabel++;
select_label();
break;
default:
break;
}
break;
case IDCMP_VANILLAKEY:
switch (Code)
{
case ESC:
Interface = FALSE;
break;
case ENTER:
click_to_front(SelectedLabel);
break;
default:
break;
}
break;
case IDCMP_REFRESHWINDOW:
GT_BeginRefresh(Win);
GT_EndRefresh(Win, TRUE);
break;
default:
break;
}
}
}
if (SigReceived & CxSigFlag)
{
while ((BrokerMsg = (CxMsg *)GetMsg(BrokerMP)))
{
MsgID = CxMsgID(BrokerMsg);
MsgType = CxMsgType(BrokerMsg);
ReplyMsg((struct Message *)BrokerMsg);
switch (MsgType)
{
case CXM_IEVENT:
switch (MsgID)
{
case EVT_HOTKEY:
open_interface();
if (Win != NULL)
{
WindowToFront(Win);
ActivateWindow(Win);
ScreenToFront(Win->WScreen);
}
break;
default:
break;
}
break;
case CXM_COMMAND:
/* Commodities has sent a command */
switch (MsgID)
{
case CXCMD_DISABLE:
/* The user clicked the Commodities Exchange */
/* disable gadget. */
ActivateCxObj(Broker, 0);
CxActive = FALSE;
break;
case CXCMD_ENABLE:
/* The user clicked the Commodities Exchange */
/* enable gadget. */
ActivateCxObj(Broker, 1);
CxActive = TRUE;
break;
case CXCMD_KILL:
/* The user clicked the Commodities Exchange */
/* kill gadget. */
Done = FALSE;
break;
case CXCMD_APPEAR:
/* The user clicked the Commodities Exchange */
/* 'Show Interface' gadget. */
open_interface();
if (Win != NULL)
{
WindowToFront(Win);
ActivateWindow(Win);
ScreenToFront(Win->WScreen);
}
break;
case CXCMD_DISAPPEAR:
/* The user clicked the Commodities Exchange */
/* 'Hide Interface' gadget */
Interface = FALSE;
break;
case CXCMD_UNIQUE:
/* The user started our Commodity twice */
open_interface();
if (Win != NULL)
{
WindowToFront(Win);
ActivateWindow(Win);
ScreenToFront(Win->WScreen);
}
break;
default:
break;
}
break;
default:
break;
}
}
}
if (SigReceived & SIGBREAKF_CTRL_C)
{
Done = FALSE;
}
}
}